package com.itheima.web;

import com.itheima.dto.CheckGroupDto;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckGroupItemService;
import com.itheima.service.CheckGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * company: www.abc.com
 * Author: 29746
 * Create Data: 2020/11/12
 */
@RestController
@RequestMapping("/checkgroup")
@Api("检查项")
public class CheckGroupController {

    @Reference
    private CheckGroupService checkGroupService;

    @Reference
    private CheckGroupItemService checkGroupItemService;

    @GetMapping("/findAll")
    @ApiOperation("查询所有检查组") //逻辑删除后修改的查询方法
    public List<CheckGroup> findAll(){
        return checkGroupService.findAll();
    }


    @PostMapping("/save")
    @ApiOperation("新增和修改检查组")
    public void save(@RequestBody CheckGroupDto  checkGroupDto){
        checkGroupService.saveGroupAndItem(checkGroupDto);
    }

    @GetMapping("/remove/{id}")
    @ApiOperation("删除检查组")
    public boolean deleteById(@PathVariable("id") Long id){
        boolean flag = checkGroupService.deleteById(id);
        return flag;
    }


    @PostMapping("/findByPage")
    @ApiOperation("分页查询检查组")
    public PageResult findByPage(@RequestBody QueryPageBean queryPageBean){
        return checkGroupService.findByPage(queryPageBean);
    }

    @GetMapping("/selectByGroupId/{groupId}")
    @ApiOperation("修改时回显检查项")
    public Long[] selectByGroupId(@PathVariable("groupId") Long groupId){
        return checkGroupItemService.selectByGroupId(groupId);
    }
}
